package com.dstation.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dstation.domain.UserInfo;
import com.dstation.domain.vo.AnalysisData;
import com.dstation.service.interf.IVideoDataAnalysisService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Objects;

@Slf4j
@Controller
@RequestMapping("/analysis")
public class VideoDataAnalysisController {
    final  int pageSize=5;
    @Resource
    private IVideoDataAnalysisService videoDataAnalysisService;


    //推荐首页
    @RequestMapping("/analysisPage")
    public  String findHomeAnalysis(HttpSession httpSession,ModelMap modelMap){
        UserInfo userInfo=(UserInfo) httpSession.getAttribute("userInfo");

        if(Objects.isNull(userInfo)){
            return "user/loginAndRegister";
        }

        long userId=userInfo.getUserId();
        //浏览数据
        List<AnalysisData> browserData=videoDataAnalysisService.findBrowserData(userId,pageSize);

        //点赞数据
        List<AnalysisData> likedData=videoDataAnalysisService.findLikedData(userId,pageSize);
        //收藏数据
        List<AnalysisData> collectData=videoDataAnalysisService.findCollectData(userId,pageSize);
        //评论数据
        List<AnalysisData> commentData=videoDataAnalysisService.findCommentData(userId,pageSize);
        //硬币数据
        List<AnalysisData> coinData=videoDataAnalysisService.findCoinData(userId,pageSize);

        //弹幕数据
        List<AnalysisData> bulletChatData=videoDataAnalysisService.findBulletChatData(userId,pageSize);


        modelMap.put("browserData",browserData);
        modelMap.put("likedData",likedData);
        modelMap.put("collectData",collectData);
        modelMap.put("commentData",commentData);
        modelMap.put("coinData",coinData);
        modelMap.put("bulletChatData",bulletChatData);
        return "main/DataAnalysis";
    }

    @RequestMapping(value = "browser")
    public String findBrowserData(@Param("page")Integer page ,HttpSession httpSession,ModelMap modelMap){
        //对特殊数据赋值
        if(Objects.isNull(page)){
            page=1;
        }
        UserInfo userInfo=(UserInfo)httpSession.getAttribute("userInfo");

        int size=10;

        IPage<AnalysisData> analysisData=videoDataAnalysisService.findAllBrowserData(userInfo.getUserId(),new Page<>(page,size));

        modelMap.put("analysisData",analysisData);
        modelMap.put("currentSearch","/analysis/browser");

        return "main/ModuleDataAnalysis";

    }

    @RequestMapping(value = "comment")
    public String findCommentData(@Param("page")Integer page ,HttpSession httpSession,ModelMap modelMap){
        //对特殊数据赋值
        if(Objects.isNull(page)){
            page=1;
        }
        UserInfo userInfo=(UserInfo)httpSession.getAttribute("userInfo");

        int size=10;

        IPage<AnalysisData> analysisData=videoDataAnalysisService.findAllCommentData(userInfo.getUserId(),new Page<>(page,size));

        modelMap.put("analysisData",analysisData);
        modelMap.put("currentSearch","/analysis/comment");

        return "main/ModuleDataAnalysis";

    }

    @RequestMapping(value = "bulletChat")
    public String findBulletChatData(@Param("page")Integer page ,HttpSession httpSession,ModelMap modelMap){
        //对特殊数据赋值
        if(Objects.isNull(page)){
            page=1;
        }
        UserInfo userInfo=(UserInfo)httpSession.getAttribute("userInfo");

        int size=10;

        IPage<AnalysisData> analysisData=videoDataAnalysisService.findAllBulletChatData(userInfo.getUserId(),new Page<>(page,size));

        modelMap.put("analysisData",analysisData);
        modelMap.put("currentSearch","/analysis/bulletChat");

        return "main/ModuleDataAnalysis";

    }

    @RequestMapping(value = "like")
    public String findLikeData(@Param("page")Integer page ,HttpSession httpSession,ModelMap modelMap){
        //对特殊数据赋值
        if(Objects.isNull(page)){
            page=1;
        }
        UserInfo userInfo=(UserInfo)httpSession.getAttribute("userInfo");

        int size=10;

        IPage<AnalysisData> analysisData=videoDataAnalysisService.findAllLikeData(userInfo.getUserId(),new Page<>(page,size));

        modelMap.put("analysisData",analysisData);
        modelMap.put("currentSearch","/analysis/like");

        return "main/ModuleDataAnalysis";
    }

    @RequestMapping(value = "coin")
    public String findCoinData(@Param("page")Integer page ,HttpSession httpSession,ModelMap modelMap){
        //对特殊数据赋值
        if(Objects.isNull(page)){
            page=1;
        }
        UserInfo userInfo=(UserInfo)httpSession.getAttribute("userInfo");

        int size=10;

        IPage<AnalysisData> analysisData=videoDataAnalysisService.findAllCoinData(userInfo.getUserId(),new Page<>(page,size));

        modelMap.put("analysisData",analysisData);
        modelMap.put("currentSearch","/analysis/coin");

        return "main/ModuleDataAnalysis";
    }

    @RequestMapping(value = "collect")
    public String findCollectData(@Param("page")Integer page ,HttpSession httpSession,ModelMap modelMap){
        //对特殊数据赋值
        if(Objects.isNull(page)){
            page=1;
        }
        UserInfo userInfo=(UserInfo)httpSession.getAttribute("userInfo");

        int size=10;

        IPage<AnalysisData> analysisData=videoDataAnalysisService.findAllCollectData(userInfo.getUserId(),new Page<>(page,size));

        modelMap.put("analysisData",analysisData);
        modelMap.put("currentSearch","/analysis/collect");

        return "main/ModuleDataAnalysis";
    }
}
